#include<bits/stdc++.h>
using namespace std;
int n,a[100000];
bool v[100000];
int ans,T;

int cnt()
{
    int c = 0;
    int lar = 0;
    int lab = 0;
    for(int i = 1;i <= n;i++)
    {
        if(v[i] == 1)
        {

            if(lab != 0)
            {
                if(a[lab] == a[i]) c+=a[i];
            }
            lab = i;
        }
        else
        {

            if(lar != 0)
            {
                if(a[lar] == a[i]) c+=a[i];
            }
            lar = i;
        }
    }
    return c;
}

void dfs(int k)
{
    if(k > n) ans = max(ans,cnt());
    else
    {
        v[k] = 1;
        dfs(k+1);
        v[k] = 0;
        dfs(k+1);
    }
}

void init()
{
    cin>>n;
    for(int i = 1;i <= n;i++) cin>>a[i];
    ans = 0;
    for(int i = 1;i <= n;i++) v[i] = 0;
}
int main()
{

    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>T;
    for(int i = 0;i < T;i++)
    {
        init();
        dfs(1);
        cout<<ans<<endl;
    }

    return 0;
}
